<template>
    <div>
    <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="资源名称">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
    <el-form-item label="资源地址">
      <el-input v-model="form.url"></el-input>
    </el-form-item>
    <el-form-item label="选择分类">
    <el-select v-model="form.pid" placeholder="请选择分类">
      <el-option label="顶级分类" value="0"></el-option>
      <el-option :label="i.name" :value="i.id" v-for="(i,x) in toplist" :key="x"></el-option>
    </el-select>
  </el-form-item>


    <el-form-item>
      <el-button type="primary" @click="onSubmit">立即创建</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
  
    </div>
  </template>
  
  <script>
    export default {
      data() {
        return {
            toplist:"",
          form: {
            name: '',
            url:"",
            pid:""
          }
        }
      },
      methods: {
        onSubmit() {
          this.axios.post("addresource",this.form).then(res =>{
            if(res.data.code == 200){
                alert(res.data.msg)
            }else{
                alert(res.data.msg)
            }
          })
        },
        getResourceCate(){
        this.axios.get("/toplist").then(res=>{
          this.toplist = res.data.data
          console.log(this.toplist)
        })
      },
      },
      mounted(){
        //数据库中获取一级分类
        this.getResourceCate()
    }
  }
  </script>
  
  <style>
  
  </style>